package org.tjc.game.snake;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Test1 {

    GameMap map = null;

    @Before
    public void init() {
        map = new GameMap(10, 10);
    }

    @Test
    public void test2() {
        AutoFindPolicy policy = new AutoFindPolicy(map);
        List<Unit> list = policy.bfs(new Unit(0, 1), new Unit(6, 5));
        System.out.println("输出路径 ： ");
        list.stream().forEach(System.out::println);
    }


    @Test
    public void test1() {
        List<Unit> list = new ArrayList<>();
//        [Unit{x=8, y=4}, Unit{x=10, y=4}, Unit{x=9, y=3}, Unit{x=9, y=5}]
        list.add(new Unit(10, 4));

        List<Unit> res = list.stream().filter(e ->
                e.getX() >= 0
                        && e.getX() < map.getH()
                        && e.getY() >= 0
                        && e.getY() < map.getW()
        ).collect(Collectors.toList());
        System.out.println(res);
    }

    @Test
    public void test4() {
        List<Integer> list = new ArrayList<>();
        list.remove(0);
    }


    //    蛇的身体：
//            [Unit{x=2, y=8}, Unit{x=3, y=8}, Unit{x=4, y=8}, Unit{x=5, y=8}, Unit{x=6, y=8}, Unit{x=7, y=8}, Unit{x=7, y=7}, Unit{x=7, y=6}, Unit{x=7, y=5}, Unit{x=7, y=4}, Unit{x=7, y=3}]
//    食物位置：
//    Unit{x=9, y=4}
//    生成最短路径是：
//            [Unit{x=2, y=8}, Unit{x=3, y=8}, Unit{x=4, y=8}, Unit{x=5, y=8}, Unit{x=6, y=8}, Unit{x=7, y=8}, Unit{x=8, y=8}, Unit{x=9, y=8}, Unit{x=9, y=7}, Unit{x=9, y=6}, Unit{x=9, y=5}, Unit{x=9, y=4}]
//    撞自己
//    p:Unit{x=3, y=8}
//    game over
    @Test
    public void test3() {
        map.updateMap(2, 8, UnitType.SNAKE);
        map.updateMap(2, 7, UnitType.SNAKE);
        map.updateMap(3, 8, UnitType.SNAKE);
        map.updateMap(9, 4, UnitType.FOOD);
        AutoFindPolicy policy = new AutoFindPolicy(map);

        System.out.println(policy.bfs(new Unit(2, 8), new Unit(9, 4)));
    }

}
